package com.jack.lib.base.header

import android.graphics.Color
import android.graphics.Typeface
import android.graphics.drawable.Drawable
import com.blankj.utilcode.util.CloneUtils
import com.jack.lib.base.header.style.GoogleStyle
import com.jack.lib.base.header.style.LightNormalStyle
import com.jack.lib.base.header.style.TransparentStyle
import com.jack.lib.core.ext.MM
import com.jack.lib.core.net.JNetView
import com.jack.lib.core.utils.ReflexUtils

/**
 * author : chong.huang
 * create : 2022/1/2
 * desc   :
 */
data class HeaderConfigurator(
    var theme: HeaderStyleTheme = JHeaderManager.defaultTheme,
    var style: IHeaderStyle = JHeaderManager.defaultStyle[theme]?.invoke()!!
): IHeaderStyle{

    operator fun get(type: IconType) = icons.find { it.type == type }

    fun addIcon(icon: HeaderIcon) = also { it.icons.add(icon) }
    fun addIcon(vararg icon:  HeaderIcon) = also { it.icons.addAll(icon) }
    fun removeIcon(icon:  HeaderIcon) = also { it.icons.remove(icon) }
    fun clearIcon() = also { it.icons.clear() }

    override var backgroundColor: Int
        get() = style.backgroundColor
        set(value) { style.backgroundColor = value }
    override var elevation: Int
        get() = style.elevation
        set(value) { style.elevation = value }
    override var width: Int
        get() = style.width
        set(value) { style.width = value }
    override var height: Int
        get() = style.height
        set(value) { style.height = value }
    override var paddingTop: Int
        get() = style.paddingTop
        set(value) { style.paddingTop = value }
    override var immersed: Boolean
        get() = style.immersed
        set(value) { style.immersed = value }
    override var icons: MutableList<HeaderIcon>
        get() = style.icons
        set(value) { style.icons = value }
}

data class HeaderIcon(
    var type: IconType,
    var drawable: Drawable? = null,
    var text: String? = null,
    var textSize: Int = 32.MM,
    var textColor: Int = Color.WHITE,
    var typeface: Typeface = Typeface.DEFAULT,
    var width: Int = type.width,
    var height: Int = type.height,
    var clickExpand: Int = 20.MM,
    var click: (() -> Unit)? = null
)


enum class HeaderStyleTheme() {
    LIGHT_NORMAL,
    TRANSPARENT,
    GOOGLE
}

enum class IconType(val width: Int, val height: Int) {
    BACK(40.MM, 40.MM),
    TITLE(-2, -2),
    TITLE_LEFT(-2, -2),
    RIGHT(40.MM, 40.MM),
    RIGHT_SECOND(40.MM, 40.MM)
}

